from aip import AipFace
import base64
import cv2
import os
import time


""" 你的 APPID AK SK """
APP_ID = '22912073'
API_KEY = '3zbPMNiqWOrsD5BspgX1pBoR'
SECRET_KEY = 'nxSoiCZnSdOV9DVTPhHrlMvAYvTHZNa4'

# 读取图片，转base64
root = 'face_test'
file_list = os.listdir(root)
for file_name in file_list:
    filepath = os.path.join(root, file_name)
    with open(filepath, "rb") as fp:
        base64_data = base64.b64encode(fp.read())
    image = str(base64_data, 'utf-8')
    imageType = "BASE64"

    # aip_face对象
    aipFace = AipFace(APP_ID, API_KEY, SECRET_KEY)

    # 配置参数
    groupIdList = 'main'
    options = {}
    options["max_face_num"] = 10
    options["match_threshold"] = 10
    options["quality_control"] = "NONE"
    options["liveness_control"] = "NONE"
    # options["user_id"] = "233451"
    options["max_user_num"] = 1

    """ 带参数调用人脸搜索 """
    response = aipFace.multiSearch(image, imageType, groupIdList, options)
    result = response['result']

    print(result)

    time.sleep(0.5)


